package com.lagou.task.servlet;

import com.lagou.task.service.StudentService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DeleteServlet", urlPatterns = "/delete")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String sId = request.getParameter("sId");
        StudentService studentService = new StudentService();
        int i = studentService.studentDelete(Integer.parseInt(sId));
        if(i>0){
            System.out.println("删除成功！");
        }
        response.sendRedirect("main.jsp");
    }
}
